<?php

namespace Api\Member\AccessLog;

use Api\RouteRegistrar;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;

/**
 * 服务提供者
 */
class ServiceProvider extends BaseServiceProvider
{
    /**
     * Boot the authentication services for the application.
     * 服务启动时执行
     * @param  Api\RouteRegistrar $api
     * @return void
     */
    public function boot(RouteRegistrar $api)
    {
        // 注册路由
        $this->registRoute($api);

    }

    /**
     * 注册路由
     * @param  Api\RouteRegistrar $api
     * @return void
     */
    private function registRoute(RouteRegistrar $api)
    {
        // 前台开放可用
        $api->member('v1', function ($api) {

            $api->group(['prefix' => 'access_logs'], function ($api) {
                // 记录一次访问
                $api->post('', Open\Controller::class.'@log');
            });

        });

        // 后台登录可用
        $api->memberManagerAuth('v1', function ($api) {

            $api->group(['prefix' => 'access_logs'], function ($api) {
                // 获取当天访问量
                $api->get('today', Manager\Controller::class.'@getToday');
            });

        });
    }

}
